package vista;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import VO.ListaPrecioCPVO;
import controlador.CasaCentral;

public class AltaOficinaVentas extends javax.swing.JFrame{
	
	private static final long serialVersionUID = 1L;
	private JLabel lblIndicar;
	private JTextField txtNombre;
	private JButton btnAceptar;
	private JLabel lblError;

	
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				PorcentajeGanancia inst = new PorcentajeGanancia();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public AltaOficinaVentas() {
		super();
		initGUI();
		CentrarJFrame();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			getContentPane().setBackground(new java.awt.Color(202,203,251));
			this.setVisible(false);
			this.setTitle("Alta Oficina de Venta");
			this.setResizable(false);
			{
				lblIndicar = new JLabel();
				getContentPane().add(lblIndicar);
				lblIndicar.setText("Indicar nombre sucursal");
				lblIndicar.setBounds(47, 22, 244, 16);
				lblIndicar.setHorizontalAlignment(SwingConstants.CENTER);
			}
			{
				txtNombre = new JTextField();
				getContentPane().add(txtNombre);
				txtNombre.setBounds(94, 50, 125, 23);
			}
			{
				btnAceptar = new JButton();
				getContentPane().add(btnAceptar);
				btnAceptar.setText("Confirmar");
				btnAceptar.setBounds(95, 102, 122, 23);
				btnAceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						
						String nombre = txtNombre.getText(); 
						
						CasaCentral.getInstancia().AltaOficinaVenta(nombre);
						lblError.setVisible(true);
						lblError.setText("Listo");
						txtNombre.setText("");
					}
				});
			}
			{
				lblError = new JLabel();
				getContentPane().add(lblError);
				lblError.setBounds(59, 75, 222, 21);
			}
			pack();
			this.setSize(327, 174);
		} catch (Exception e) {
		 
			e.printStackTrace();
		}
	}

	private void CentrarJFrame(){
		
	    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
	    
	    
	    int w = this.getSize().width;
	    int h = this.getSize().height;
	    int x = (dim.width-w)/2;
	    int y = (dim.height-h)/2;
	    
	    
	    this.setLocation(x, y);
	}

}
